<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>网页时钟</title>
    <style>
        * {
            box-sizing: border-box;
        }

        .clock {
            width: 600px;
            height: 600px;
            background: url(../images/clock.jpg) no-repeat;
            margin: 50px auto 0;
            position: relative;
        }

        .hh,
        .mm,
        .ss {
            position: absolute;
            width: 100%;
            height: 100%;
            left: 0;
            top: 0;
            background: url(../images/hour.png) no-repeat center;
        }

        .hh {
            transform: rotate(0deg);
        }

        .mm {
            background-image: url(../images/minute.png);
            transform: rotate(0deg);
        }

        .ss {
            background-image: url(../images/second.png);
            transform: rotate(0deg);
        }
    </style>
</head>

<body>
    <div class="clock">
        <div class="hh" id="h"></div>
        <div class="mm" id="m"></div>
        <div class="ss" id="s"></div>
    </div>

    <script>
        // 获取元素标签
        const second = document.querySelector('.ss');
        const mm = document.querySelector('.mm');
        const hh = document.querySelector('.hh');

        // 定时器，每隔一秒钟调用getTime()函数获取实时时间
        setInterval(getTime, 1000);
        // 调用函数渲染页面，打开时就显示当前时间
        getTime();

        function getTime() {
            let date = new Date();//获取当前时间
            let h = date.getHours(); //获取时
            let m = date.getMinutes();//获取分
            let s = date.getSeconds();//获取秒
            let hDeg = (h * 3600 + m * 60 + s) / (3600 * 12) * 360;//时针角度
            let mDeg = (m * 60 + s) / 3600 * 360;//分针角度
            let sDeg = 360 / 60 * s;//秒针角度
            second.style.transform = `rotate(${sDeg}deg)`;
            hh.style.transform = `rotate(${hDeg}deg)`;
            mm.style.transform = `rotate(${mDeg}deg)`;
        };
    </script>
</body>

</html>